﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Web.App.Infrastructure.ApplicationMessages.Contracts;
using Web.App.Infrastructure.ApplicationMessages.Implementation;

namespace Web.App.Infrastructure.ApplicationMessages.Builder
{
    public class BuildFailureMessage
    {
        private string _context = string.Empty;
        private string _action = string.Empty;
        private List<IFailure> _failures = new List<IFailure>();
        private string _messageKey = string.Empty;

        public BuildFailureMessage WithContext(string context)
        {
            _context = context;
            return this;
        }

        public BuildFailureMessage WithAction(string action)
        {
            _action = action;
            return this;
        }

        public BuildFailureMessage WithFailure(IFailure failure)
        {
            _failures.Add(failure);
            return this;

        }

        public BuildFailureMessage WithFailures(IEnumerable<IFailure> failures)
        {
            _failures.AddRange(failures);
            return this;

        }

        public BuildFailureMessage WithMessageKey(string messageKey)
        {
            this._messageKey = messageKey;
            return this;
        }

        private FailureMessage Build()
        {
            return new FailureMessage( _failures, _context, _action, _messageKey);
        }

        public static implicit operator FailureMessage(BuildFailureMessage builder)
        {
            return builder.Build();
        }
    }
}